<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
    <h4 class="modal-title">{{ trans('classes-pages.creation-title') }}</h4>
</div>
<div class="portlet modal-body portlet-body form">
    <!-- BEGIN FORM-->
    <form action="{{ route('class-create')}}" class="form-horizontal" id="form-classes" method="post">
        <div class="form-body">
            <div class="alert alert-danger display-hide">
                <button class="close" data-close="alert"></button>
                <span></span>
            </div>
            <div class="alert alert-success display-hide">
                <button class="close" data-close="alert"></button>
                <span></span>
            </div>
            <div class="form-group" style="margin-left: 0; margin-right: 0;">
                <label class="control-label col-md-3" for="course">{{ trans('classes.course') }}</label>
                <div class="col-md-7">
                    <select name="course" id="course" class="form-control">
                        @foreach($aCourse as $sKey => $sValue)
                        <option value="{{{$sKey}}}">{{{$sKey}}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-left: 0; margin-right: 0;">
                <label class="control-label col-md-3" for="team">{{ trans('classes.team') }}</label>
                <div class="col-md-7">
                    <select name="team" id="team" class="form-control">
                        @foreach($aTeams as $sKey => $sValue)
                        <option value="{{ $sValue->key }}">{{ $sValue->data }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-left: 0; margin-right: 0;">
                <label class="control-label col-md-3" for="level">{{ trans('classes.level') }}</label>
                <div class="col-md-7">
                    <select name="level" id="level" class="form-control">
                        @foreach($aLevels as $sKey => $sValue)
                        <option value="{{ $sValue->key }}">{{ $sValue->data }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-left: 0; margin-right: 0;">
                <label class="control-label col-md-3" for="crew">{{ trans('classes.crew') }}</label>
                <div class="col-md-7">
                    <select name="crew" id="crew" class="form-control">
                        <option value=""></option>
                        @foreach($aCrews as $sKey => $sValue)
                        <option value="{{ $sValue->key }}">{{ $sValue->data }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="form-group" style="margin-left: 0; margin-right: 0;">
                <label class="control-label col-md-3" for="location">{{ trans('classes.location') }}</label>
                <div class="col-md-7">
                    <input type="text" name="location" id="location" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-left: 0; margin-right: 0;">
                <label class="control-label col-md-3" for="note">{{ trans('system.note') }}</label>
                <div class="col-md-7">
                    <textarea name="note" id="note" class="form-control"></textarea>
                </div>
            </div>
        </div>
    </form>
    <!-- END FORM-->
</div>
<div class="modal-footer">
    <button type="button" class="btn default" data-dismiss="modal">{{ trans('system.button.cancel') }}</button>
    <button type="button" class="btn blue btn-class-create">{{ trans('system.button.submit') }}</button>
</div>
<script type="text/javascript">
    
    var form = $('#form-classes');
    var error = $('.alert-danger', form);
    var success = $('.alert-success', form);
    
    form.keypress(function(e) {
        if (e.which == '13') {
            $('.btn-class-create').trigger('click');
            return false;
        }
    });

    $('.btn-class-create').click(function () {
        $.ajax({
            url: form.attr('action'),
            type: form.attr('method'),
            data: form.serialize(),
            dataType: 'json'
        }) .done(function(response) {
            if (response.status == 200) {
                success.find('span').text(response.message);
                success.show();
                error.hide();
            }
            else {
                error.find('span').text(response.message);
                error.show();
                success.hide();
            }
        })
        .fail(function() {
            error.find('span').text('Check Your Connection.');
            error.show();
            success.hide();
        });
    });
</script>